//校验点位  小数点最多前两位  小数点后两位
window.ParsleyValidator.addValidator('point', function(value) {
    if(value!= ""){
        return /^([1-9]\d{0,1}|0)(\.\d{1,2})?$/.test(value);

    }
    return true;
},32);

//数字  小数点  限制小数点前9位 小数点后两位
window.ParsleyValidator.addValidator('money', function(value) {
    if(value!= ""){
        return /^([1-9]\d{0,8})$|^([1-9]\d{0,8}\.\d{1,2})$/.test(value);

    }
    return true;
},32);
//限制文件大小
window.Parsley.addValidator('maxFileSize', {
    validateString: function(_value, maxSize, parsleyInstance) {
        if (!window.FormData) {
            alert('You are making all developpers in the world cringe. Upgrade your browser!');
            return true;
        }
        var files = parsleyInstance.$element[0].files;
        return files.length != 1  || files[0].size <= maxSize * 1024;
    },
    requirementType: 'integer',
    messages: {
        en: 'This file should not be larger than %s Kb'
    }
});
//限制文件大小
window.Parsley.addValidator('fileType', {
    validateString: function(_value, fileTypes, parsleyInstance) {
        if (!window.FormData) {
            alert('You are making all developpers in the world cringe. Upgrade your browser!');
            return true;
        }
        var files = parsleyInstance.$element[0].files;
        if(files.length == 1){
            var fileName = files[0].name;
            var fileType = fileName.substring(fileName.lastIndexOf("."),fileName.length);
            return fileTypes.indexOf(fileType)>=0;
        }else {
            return false;
        }
    },
    requirementType: 'string',
    messages: {
        en: 'This file type must be  %s '
    }
});



//渠道校验开始
window.ParsleyValidator.addValidator('companyname', function (value) {
    if (value != "") {
        return /^[a-zA-Z0-9\u4E00-\u9FA5]+$/.test(value);
    }
    return true;
}, 32);

window.ParsleyValidator.addValidator('creditcode', function (value) {
    if (value != "") {
        return /[A-Z0-9]{18}/g.test(value);
    }
    return true;
}, 32);

window.ParsleyValidator.addValidator('legalpersonname', function (value) {
    if (value != "") {
        return /^[\u0391-\uFFE5A-Za-z]+$/.test(value);
    }
    return true;
}, 32);

window.ParsleyValidator.addValidator('legalpersonidno', function (value) {
    if (value != "") {
        return /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/.test(value);
    }
    return true;
}, 32);
window.ParsleyValidator.addValidator('legalpersonmobile', function (value) {
    if (value != "") {
        return /^1\d{10}$/.test(value);
    }
    return true;
}, 32);
window.ParsleyValidator.addValidator('telephone', function (value) {
    if (value != "") {
        var b = value.length;
        return (b == 11 && /^1\d{10}$/.test(value)) || (b >= 10 && b <= 13 && /^0\d{2}-\d+$/.test(value))
            || (b >= 10 && b <= 13 && /^0\d{3}-\d+$/.test(value) || (b >= 10 && b <= 13 && /^0\d{2}\d+$/.test(value)));
    }
    return true;
}, 32);

window.ParsleyValidator.addValidator('only', function (jobNumber) {
    var result = true;
    if (jobNumber != "" && jobNumber != null) {
        $.ajax({
            type: "post",
            url: "/channel/onlyJobNumber",
            async: false,
            data: {jobNumber: jobNumber},
            success: function (msg) {
                if (msg.success != true) {
                    result = false;
                }
            }
        });
    }
    return result;
}, 32);

window.ParsleyValidator.addValidator('jobnumber', function (value) {
    if (value != "") {
        return /^[0-9a-zA-Z]*$/g.test(value);
    }
    return true;
}, 32);

window.ParsleyValidator.addValidator('contactcompanyname', function (value) {
    if (value != "") {
        return /^[A-Za-z0-9\u4e00-\u9fa5]+$/.test(value);
    }
    return true;
}, 32);

window.ParsleyValidator.addValidator('accountname', function (value) {
    if (value != "") {
        return /^[a-zA-Z\u4e00-\u9fa5]+$/.test(value);
    }
    return true;
}, 32);

window.ParsleyValidator.addValidator('accountno', function (value) {
    if (value != "") {
        return /^[0-9]*$/.test(value);
    }
    return true;
}, 32);

window.ParsleyValidator.addValidator('bankname', function (value) {
    if (value != "") {
        return /^[a-zA-Z0-9\u4E00-\u9FA5]+$/.test(value);
    }
    return true;
}, 32);

window.ParsleyValidator.addValidator('bankbranchname', function (value) {
    if (value != "") {
        return /^[a-zA-Z0-9\u4E00-\u9FA5]+$/.test(value);
    }
    return true;
}, 32);

window.ParsleyValidator.addValidator('alipayno', function (value) {
    if (value != "") {
        return ( /^[a-zA-Z0-9]+$/.test(value) || /^[a-zA-Z0-9_.-]+@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*\.[a-zA-Z0-9]{2,6}$/.test(value));
    }
    return true;
}, 32);

window.ParsleyValidator.addValidator('wechatno', function (value) {
    if (value != "") {
        return (/^[a-zA-Z][a-zA-Z0-9_-]{5,19}$/.test(value) || /^[a-zA-Z0-9]+$/.test(value));
    }
    return true;
}, 32);


window.ParsleyValidator.addValidator('filetype', function (value) {
    if (value != "") {
        return /\.(jpg|pdf|png|doc|docx|JPG|PDF|PNG|DOC|DOCX)$/.test(value);
    }
    return true;
}, 32);
//渠道校验信息结束
window.ParsleyValidator.addValidator('homeaddress', function (value) {
    if (value != "") {
        return /^[\u4E00-\u9FA5A-Za-z\d\-]+$/.test(value);
    }
    return true;
}, 32);



